package com.waves.thread;

import java.util.concurrent.*;

public class ThreadDemo {

    public static void main(String[] args) {
        // 1.使用Thread
        new Thread01().start();
        // 2.使用Runnable
        Runnable01 runnable01 = new Runnable01();
        new Thread(runnable01).start();
        // 使用线程池
        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(100);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
                10,
                10,
                TimeUnit.SECONDS,
                workQueue);
        executor.execute(() -> System.out.println("线程池 线程名称：" + Thread.currentThread().getName()));
        // 使用CompletableFuture
        CompletableFuture.runAsync(() -> System.out.println("CompletableFuture线程名称：" + Thread.currentThread().getName()));
    }


}

class Thread01 extends Thread {
    @Override
    public void run() {
        System.out.println("继承Thread线程名称:" + Thread.currentThread().getName());
    }
}

class Runnable01 implements Runnable {
    @Override
    public void run() {
        System.out.println("实现Runnable线程名称:" + Thread.currentThread().getName());
    }
}